package com.example.myapplication;



import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import androidx.fragment.app.DialogFragment;

public class FireMissilesDialogFragment extends DialogFragment {

    EditText editText1 = null;
    EditText editText2 = null;
    NotifyDialogListener listener = null;

    public interface NotifyDialogListener
    {
        public void onDialogPositiveClicked(String text1, String text2);
        public void onDialogNegativeClicked();
    }
    public void setListener(NotifyDialogListener listener){
        this.listener = listener;
    }


    public Dialog onCreateDialog(Bundle saveInstanceState){

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = requireActivity().getLayoutInflater();

        View view = inflater.inflate(R.layout.activity_main2,null);
        editText1 = view.findViewById(R.id.editTextTextPersonName);
        editText2 = view.findViewById(R.id.editTextTextPersonName2);

        builder.setView(view);
        builder.setTitle("自定义对话框");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                listener.onDialogPositiveClicked(editText1.getText().toString(),editText2.getText().toString());
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                listener.onDialogNegativeClicked();
            }
        });
        return builder.create();
    }
}
